<?php defined('BASEPATH') OR exit('No direct script access allowed');

/**
 * M_verificationlink
 *
 * This is an M_clickverificationlink of a few basic verificationlink interaction methods you could use
 * all done with a hardcoded array.
 *
 * @package		CodeIgniter
 * @subpackage	Rest Server
 * @category	Controller
 * @author		Phil Sturgeon
 
*/

// This can be removed if you use __autoload() in config.php OR use Modular Extensions
require APPPATH.'/libraries/REST_Controller.php';

class Clickverificationlink extends REST_Controller
{
	function __construct()
	{
		parent::__construct();
		$this->load->model('mdl_clickverificationlink');
		
	}

   /* function verificationlink_post()
    {
        //$this->some_model->updateverificationlink( $this->get('id') );
     
		
$data['username']=$this->post('username'); 
$data['password']=$this->post('password'); 
$data['level_id']=$this->post('level_id'); 



		$query = $this->mdl_verificationlink->insert($data);
		
	
		if ($query){
			
			$this->response(array('status' => 'true'),200);
		}else{
			$this->response(array('status' => 'false'));
		}

    }
	*/
	
	/*function check_clickverificationlink_post(){
		      

		//post
		
		$username=$this->post('username'); 
		$appsidonapps=$this->post('appsid'); 
         $query = $this->mdl_verificationlink->updateresenddate($username);
		
	
		$resendstatus = 'true';
		$resendnotification = 'Link verifikasi sudah dikirim ke email anda. Silahkan cek kembali.';
		$debug = 'debug';
		
		
		
	
			$debug = 'kirim via email link nya';
			
		
		$this->response(array( 'username' => $username ,'appsidonapps' => $appsidonapps , 'resendstatus' => $resendstatus, 'resendnotification' => $resendnotification,  'debug' => $debug));
	}*/
    /*
    function verificationlink_delete()
    {
		
    	//$this->some_model->deletesomething( $this->get('id') );$this->_get('id')
        $message = array('message' => 'DELETED!', 'id'=>$this->delete('id'));
		
		$query = $this->mdl_verificationlink->delete($this->delete('id'));
		//$this->response($message,200);
		//$query=1;
		if ($query){
			$this->response(array('status' => 1),200);
		
		}else{
			$this->response(array('status' => 0));
		}
      
    } */
	/*
	 function verificationlink_put()
    {
		
    	//$this->some_model->deletesomething( $this->get('id') );$this->_get('id')
        //$message = array('message' => 'UPDATE!', 'userid'=>$this->delete('userid'), 'name'=>$this->delete('name'));
		$data['userid']=$this->put('userid'); 
$data['username']=$this->put('username'); 
$data['password']=$this->put('password'); 
$data['level_id']=$this->put('level_id'); 

		$query = $this->mdl_verificationlink->update($data['userid'],$data);
		//$this->response($message,200);
		
		if ($query){
			$this->response(array('status' => 1),200);
		
		}else{
			$this->response(array('status' => 0));
		}
      
    } */
    
    function check_clickverificationlink_get()
    {
 
		$this->load->helper('jwt_helper');
		$token = JWT::decode($_GET['token'], 'dompeto');
		$appsidonappstoken= $token->appsidonapps;
        $usernametoken= $token->username;
      
		$arrwhere="username = '" . $usernametoken  . "'";
		$query = $this->mdl_clickverificationlink->get_item(0, 0, $arrwhere);
		$result = $query->result_array('verificationtoken');
		$verificationtoken = $result[0]['verificationtoken'];
		
		if($_GET['token']==$verificationtoken) {
		
		
		
		$arrwhere="username = '" . $usernametoken  ."'";
		$query = $this->mdl_clickverificationlink->get_item(0, 0, $arrwhere);
		
		
			if ($query->num_rows() > 0)
		{
			$i=0;
			foreach($query->result_array() as $row)
			{
				$rows[$i]['verificationstatus'] = $row['verificationstatus'];
				$i++;
			}
			}
			
		$verificationstatus = $rows[0]['verificationstatus'];
		if ( $verificationstatus== 0) {
	
		$verificationstatus = 'true';	
		$query = $this->mdl_clickverificationlink->updateverificationstatus($usernametoken);	

			$debug = '  token sama, sukses verifikasi';
		} else {
		$debug = '  token sama, tapi udah pernah verifikasi';
		$verificationstatus = 'false';

		}
		
		
		
		
		
		} else {
		
		 $verificationstatus = 'false';
		$debug ='token beda' ;
		
		}
		
		
        $this->response(array( 'verificationstatus' => $verificationstatus, 'debug' => $debug));
      
    } 
/*

	public function send_post()
	{
		var_dump($this->request->body);
	}
*/
/*
	public function send_put()
	{
		var_dump($this->put('foo'));
	}
	*/
}